package com.xulu.romance.controller;

import com.xulu.romance.pojo.Dept;
import com.xulu.romance.service.DeptService;
import com.xulu.romance.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaoxulu
 * @version V1.0
 * @Package com.xulu.romance.controller
 * @date 2025/6/3 13:17
 */
@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping("")
    public R findAll(){
        List<Dept> deptList = deptService.list();
        return R.ok().put("data", deptList);
    }

    @GetMapping("{id}")
    public R findById(@PathVariable Integer id){
        Dept dept = deptService.getById(id);
        return R.ok().put("data", dept);
    }

    @PostMapping
    public R add(@RequestBody Dept dept){
        deptService.save(dept);
        return R.ok();
    }

    @PutMapping
    public R edit(@RequestBody Dept dept){
        deptService.updateById(dept);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable Integer id){
        deptService.removeById(id);
        return R.ok();
    }
}
